perm filename NEW.TEX[FTL,LSP] blob sn#848139 filedate 1987-11-05 generic text, type T, neo UTF8
\input macros
\def\methodlabel
#1:{\noindent\hbox to 0pc{\bf\hskip-\hcomleftskip #1:\hss}\ignorespaces}

%\def\methodrule{\Vskip 1pc!\hrule\Vskip 1pc!}

\begincom{add-method}\ftype{Standard Generic Function}

\label Generic Function Syntax:

\Defgen {add-method} {generic-function method}

\label Method Signatures:

\Defmeth {add-method} {\vtop{\hbox{({\it generic-function\/} standard-generic-function)}
\hbox{({\it method\/} standard-method)}}}

\label Purpose:

The generic function {\bf add-method} adds a method to a generic
function.  

\methodrule

\label Method:

\Defmeth {add-method} {\vtop{\hbox{({\it generic-function\/} standard-generic-function)}
\hbox{({\it method\/} standard-method)}}}

\methodlabel Purpose:

This method for {\bf add-method} adds a method to a generic
function.  It destructively modifies the generic function and returns
the modified generic function as its result.

\methodlabel Arguments:

The {\it generic-function\/} argument is a generic function
object.

The {\it method\/} argument is a method object.  The lambda-list of
the method function must be congruent with the lambda-lists of all
other methods associated with the generic function and with the
lambda-list of the generic function, or else an error is signaled.

\methodlabel Values:

The modified generic function is returned.  The result
is {\bf eq} to the {\it generic-function\/} argument.

\methodlabel Remarks:

If the given method is already one of the methods of the generic
function, if the method corresponds in parameter specializers and
method qualifiers to an existing method of the generic
function, or if the method object is a method object of another
generic function, an error is signaled.

%\methodrule
\vfill\eject

\label See Also:

{\bf defmethod

defgeneric}

\endcom


\begincom{change-class}\ftype{Standard Generic Function}

\label Generic Function Syntax:

\Defgen {change-class} {instance new-class}

\label Method Signatures:

\Defmeth {change-class} {({\it instance\/} standard-object) ({\it new-class\/} standard-class)}

\Defmeth {change-class} {({\it instance\/} standard-object) ({\it new-class\/} symbol)}

\label Purpose:

The generic function {\bf change-class} changes the class of an
instance to a new class.

\methodrule

\label Method:

\Defmeth {change-class} {({\it instance\/} standard-object) ({\it new-class\/} standard-class)}

\methodlabel Purpose:

This method for {\bf change-class} changes the class of an instance to
a new class.  It destructively modifies and returns the instance.

If in the old class there is any slot of the same name as a local
slot in the new class, the value of that slot is retained.  This
means that if the slot has a value, the value returned by {\bf
slot-value} after {\bf change-class} is invoked is {\bf eql} to the
value returned by {\bf slot-value} before {\bf change-class} is
invoked.  Similarly, if the slot was uninitialized, it remains
uninitialized.  The other slots are initialized as described in the
section ``Changing the Class of an Instance.''

\methodlabel Values:

The modified instance is returned.  The result
is {\bf eq} to the {\it instance} argument.

\methodlabel Remarks:

After completing all other actions, this method on {\bf change-class}
invokes the generic function {\bf class-changed}.  The generic
function {\bf class-changed} can be used to assign values to slots
in the transformed instance.

This method on {\bf change-class} has several semantic difficulties.
First, it performs a destructive operation that can be invoked within a
method on an instance that was used to select that method. When multiple
methods are involved because methods are being combined,
the methods currently executing or about to be executed
may no longer be applicable.  Second, some implementations might use compiler
optimizations of slot access, and when the class of an instance is
changed the assumptions the compiler made might be violated.
This implies that a programmer must not use this method on {\bf
change-class} inside a method if any methods for that generic function 
access any slots, or else the results are undefined.

\methodrule

\label Method:

\Defmeth {change-class} {({\it instance\/} standard-object) ({\it new-class\/} symbol)}

\methodlabel Purpose:

This method invokes {\bf change-class} on {\it instance}
and {\tt (symbol-class {\it symbol\/})}.

\methodlabel Arguments:

The {\it new-class\/} argument is a symbol that names a class.

\methodrule

\label Examples:

\screen!

(defclass position () ())

(defclass x-y-position (position)
    ((x :initform 0 :initarg :x)
     (y :initform 0 :initarg :y)))

(defclass rho-theta-position (position)
    ((rho :initform 0)
     (theta :initform 0)))

(defmethod class-changed ((old x-y-position) 
                          (new rho-theta-position))
  ;; Copy the position information from old to new to make new
  ;; be a rho-theta-position at the same position as old.
  (let ((x (slot-value old 'x))
        (y (slot-value old 'y)))
    (setf (slot-value new 'rho) (sqrt (+ (* x x) (* y y)))
          (slot-value new 'theta) (atan y x))))

;;; At this point an instance of the class x-y-position can be
;;; changed to be an instance of the class rho-theta-position using
;;; change-class:

(setq p1 (make-instance 'x-y-position :x 2 :y 0))

(change-class p1 'rho-theta-position)

;;; The result is that the instance bound to p1 is now an instance of
;;; the class rho-theta-position.   The method for class-changed
;;; performed the initializion of the rho and theta slots based
;;; on the value of the x and y slots, which were maintained by
;;; the old instance.

\endscreen!

\label See Also:
 
``Changing the Class of an Instance''

{\bf class-changed}

\endcom


\begincom{class-changed}\ftype{Standard Generic Function}

\label Generic Function Syntax:

\Defgen {class-changed} {previous current}

\label Method Signatures:

\Defmeth {class-changed} {({\it previous\/} standard-object) ({\it current\/} standard-object)}

\label Purpose:

The generic function {\bf class-changed} is invoked when an instance is
transformed from the old version of a class to the new version.

The generic function {\bf class-changed} is not intended to be called
by programmers.  Programmers are expected to write methods for it.
The function {\bf class-changed} is called only by the function {\bf
change-class}.  

\label Arguments:
The arguments to {\bf class-changed} are computed by {\bf
change-class}.  When the {\bf change-class} method that is specialized
on {\bf standard-object} and {\bf standard-class} is invoked on an
instance, a copy of that instance is made; the {\bf change-class}
method then destructively alters the original instance.  The first
argument to {\bf class-changed}, {\it previous\/}, is that copy; it
holds the old slot values temporarily.  This argument has dynamic
extent within {\bf change-class}; if it is referenced in any way once
{\bf class-changed} returns, the results are undefined.  The second
argument to {\bf class-changed}, {\it current}, is the altered
original instance.

The typical use of {\it previous\/} is to extract old slot values by using
{\bf slot-value} or {\bf with-slots} or by invoking an accessor generic
function, or to run other methods that were applicable to instances of
the original class.

\label Values:

The value returned by {\bf class-changed} is ignored by the {\bf change-class}
method.

\methodrule

\label Method:

\Defmeth {class-changed} {({\it previous\/} standard-object) ({\it current\/} standard-object)}

\methodlabel Purpose:

This method on {\bf class-changed} initializes the newly-added
slots when an instance is transformed from the old version of a class
to the new version.

Each local slot of the new version of the class with no slot by the
same name in the old version of the class is initialized to the value
of the corresponding {\bf :initform} option of the new class or
remains uninitialized if the new version of the class does not specify
or inherit the {\bf :initform} option for that slot.

\methodrule

\label Examples:

See the example for the function {\bf change-class}.

\label See Also:

``Changing the Class of an Instance''

{\bf change-class}

\endcom



\begincom{class-name}\ftype{Standard Generic Function}

\label Generic Function Syntax:

\Defgen {class-name} {class}

\label Method Signatures:

\Defmeth {class-name} {({\it class\/} standard-class)}

\label Purpose:

The generic function {\bf class-name} takes a class object and returns its
name.

\methodrule

\label Method:

\Defmeth {class-name} {({\it class\/} standard-class)}

\methodlabel Purpose:

This method takes a standard class and returns its name.

\methodlabel Arguments:

The {\it class\/} argument is a class object.

\methodlabel Values:

The name of the given class is returned; this result is a
symbol.

\methodrule

\label Remarks:

The name of an anonymous class is {\bf nil}.

If $S =${\tt (class-name $C$)} and $C =${\tt (symbol-class $S$)},
then $S$ is the proper name of $C$.

\label See Also:

{\bf symbol-class}

\endcom

\begincom{describe}\ftype{Standard Generic Function}

\label Generic Function Syntax:

\Defgen {describe} {object}

\label Method Signatures:

\Defmeth {describe} {({\it object\/} t)}

\Defmeth {describe} {({\it object\/} standard-object)}

\label Purpose:

The Common Lisp function {\bf describe} is replaced by a generic
function.  The generic function {\bf describe} prints information
about a given object on the standard output.

Each implementation is required to provide a default method, that is,
a method for the class {\bf t}, and a method for the class {\bf
standard-object}.  Implementations are free to add methods for
specific classes.  Users can write methods for {\bf describe} for
their own classes if they do not wish to inherit an
implementation-supplied method.  These methods must conform to the
definition of {\bf describe} as specified in {\it Common Lisp: The
Language}.

\label Values:

The generic function {\bf describe} returns no values.

\methodrule

\label Method:

\Defmeth {describe} {({\it object\/} t)}

\methodlabel Purpose:

This method prints information about the given object on the standard output.

\methodlabel Arguments:

The {\it object\/} argument may be any Common Lisp object. 

%\methodrule
\vfill\eject

\label Method:

\Defmeth {describe} {({\it object\/} standard-object)}

\methodlabel Purpose:

This method prints information about the given instance of {\bf
standard-object} on the standard output.

\methodlabel Arguments:

The {\it object\/} argument may be any standard object. 

\endcom

\endChapter
\bye